package com.wwp.tbshop.presenter;

import android.util.Log;

import com.wwp.tbshop.activity.LimitBuyActivity;
import com.wwp.tbshop.model.bean.BaseBean;
import com.wwp.tbshop.model.bean.LimitBuyBean;

import java.util.List;

import retrofit2.Call;

/**
 * Created by ${wenping} on 6/16/2017.
 */

public class LimitBuyPresenter extends BasePresenter {

    private LimitBuyActivity mLimitBuyActivity;
    private boolean openLog = true;
    private List<LimitBuyBean.ProductListBean> mProductList;

    public LimitBuyPresenter(LimitBuyActivity limitBuyActivity) {
        mLimitBuyActivity = limitBuyActivity;
    }

    public void loadLimitBuyGoods(int page,int num){
        Call<LimitBuyBean> limtBuyGoodsCall = mApiService.getLimtBuyGoods(page+"", num+"");
        limtBuyGoodsCall.enqueue(mCallback);
    }

    @Override
    protected void onServerBug(int code) {
        if (openLog) {
            Log.e(TAG, "onServerBug "+code);
        }
    }

    @Override
    protected void onConnectError(String message) {
        if (openLog) {
            Log.e(TAG, "onConnectError ");
        }
    }

    private static final String TAG = "LimitBuyPresenter";
    @Override
    protected void onSuccess(BaseBean bean) {
        if (openLog) {
            Log.e(TAG, "onSuccess ");
            LimitBuyBean mLimitBuyBean = (LimitBuyBean) bean;
            if (mLimitBuyBean!=null){
                mProductList = mLimitBuyBean.getProductList();
                mLimitBuyActivity.onLimitBuySuccess(mProductList);
            }else{
                Log.e(TAG, "数据请求失败"+mLimitBuyBean.getError()+";"+mLimitBuyBean.getError_code());
            }
        }
    }
}
